
/**
*┌──────────────────────────────────────────────────────────────┐
*│　描    述：                                                    
*│　作    者：gaotang                                            
*│　版    本：1.0    模板代码自动生成                                                
*│　创建时间：2019-01-04 10:01:02                             
*└──────────────────────────────────────────────────────────────┘
*┌──────────────────────────────────────────────────────────────┐
*│　命名空间： BestTrader.Cms.Services                                  
*│　类    名： SysItemsDetailService                                    
*└──────────────────────────────────────────────────────────────┘
*/
using AutoMapper;
using BestTrader.Cms.IRepository;
using BestTrader.Cms.IServices;
using BestTrader.Cms.ViewModels;
using System;
using System.Collections.Generic;
using System.Text;

namespace BestTrader.Cms.Services
{
    public class SysItemsDetailService: ISysItemsDetailService
    {
        private readonly IMapper _mapper;
        private readonly ISysItemsRepository _repository;
        private readonly ISysItemsDetailRepository _itemRepository;

        public SysItemsDetailService(IMapper mapper, ISysItemsRepository repository, ISysItemsDetailRepository itemRepository)
        {
            _mapper = mapper;
            _repository = repository;
            _itemRepository = itemRepository;
        }

        public List<ItemsDetailModel> GetItems(string parentCode)
        {
            var result = new List<ItemsDetailModel>();
            var item = _repository.Get($"SELECT * FROM [dbo].[SysItems] WHERE EnCode = '{ parentCode }'");
            if (item != null)
            {
                var itemDetails = _itemRepository.GetList($"where ParentId = { item.Id }");
                result = _mapper.Map<List<ItemsDetailModel>>(itemDetails);
            }
            return result;
        }
    }
}